<template>
  <div class="app-container">
    <!--查询-->
    <el-form :inline="true">
      <el-form-item label=" 父级菜单">
        <el-input
          v-model="searchForm.parentId"
          placeholder=" 父级菜单"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        />
      </el-form-item>
      <el-form-item label=" 菜单名称">
        <el-input
          v-model="searchForm.title"
          placeholder=" 菜单名称"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        />
      </el-form-item>
      <el-form-item label=" 路由地址">
        <el-input
          v-model="searchForm.routeUrl"
          placeholder=" 路由地址"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        />
      </el-form-item>
      <el-form-item label="状态">
        <el-select
          v-model="searchForm.hiddenFlag"
          placeholder=" 展示"
          clearable
          @blur="fetchList"
          @keyup.enter.native="fetchList"
        >
          <el-option label="展示" value="0" />
          <el-option label="隐藏" value="1" />
        </el-select>
      </el-form-item>
      <search-buttons
        :fetch-data="fetchList"
        :export-flag="false"
        :add-fun="addMenu"
      />
    </el-form>
    <!--表格-->
    <el-table :data="tableData" border stripe>
      <el-table-column type="index" width="50" label="序号" />
      <el-table-column prop="title" label=" 菜单名称" />
      <el-table-column prop="parentId" label="父级菜单" />
      <el-table-column prop="name" label=" 路由名称" />
      <el-table-column prop="redirect" label="重定向地址" />
      <el-table-column prop="path" label="路由地址" />
      <el-table-column prop="component" show-overflow-tooltip label="组件地址" />
      <el-table-column prop="icon" label=" icon" />
      <el-table-column prop="alwaysShow" width="100" label="无子集状态">
        <template slot-scope="scope">
          <span v-if="scope.row.alwaysShow">展示</span>
          <span v-if="!scope.row.alwaysShow">隐藏</span>
        </template>
      </el-table-column>
      <el-table-column prop="hidden" width="80" label="是否隐藏">
        <template slot-scope="scope">
          <span v-if="scope.row.hidden">展示</span>
          <span v-if="!scope.row.hidden">隐藏</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="260">
        <template slot-scope="scope">
          <operation-buttons
            :row="scope.row"
            :del-fun="delSysMenuById"
            :detail-fun="menuDetail"
            :edit-fun="editMenu"
          />
        </template>
      </el-table-column>
    </el-table>
    <div>
      <!-- 分页 -->
      <pagination
        :page.sync="searchForm.currentPage"
        :total="total"
        :limit.sync="searchForm.pageSize"
        @pagination="fetchList"
      />
    </div>
  </div>
</template>
<script>
import sysMenu from '@/api/sysMenu'
import Pagination from '@/components/Pagination/index'
import SearchButtons from '@/components/SearchButtons/index'
import OperationButtons from '@/components/OperationButtons/index'
import {popAutoHeightDialog, popDialog} from '@/utils/popDialog'

export default {
  components: {
    Pagination,
    SearchButtons,
    OperationButtons
  },
  data() {
    return {
      name: 'SysMenu',
      searchForm: {
        currentPage: 1,
        pageSize: 10
      },
      total: 0,
      tableData: []
    }
  },
  created() {
    this.fetchList()
  },
  methods: {
    fetchList() {
      sysMenu.fetchList({ ...this.searchForm }).then(resp => {
        this.tableData = resp.data.data
        this.total = resp.data.total
        this.searchForm.pageNum = resp.data.pageNum
        this.searchForm.currentPage = resp.data.currentPage
      })
    },
    delSysMenuById(id) {
      sysMenu.delById(id).then(resp => {
        this.$message.info(resp.message)
      })
    },
    clearSearchForm() {
      this.searchForm = {}
    },
    downloadTemplate() {
      // window.location.href = 'http://localhost:9527/sysMenu/template'
      window.location.href = 'http://localhost:9527/sysMenu/template'
    },
    export2Excel() {
      sysMenu.export2Excel({ ...this.searchForm })
    },
    addMenu() {
      this.popFormDialog(0, null, '新增菜单')
    },
    editMenu(id) {
      this.popFormDialog(1, id, '编辑菜单')
    },
    menuDetail(id) {
      this.popFormDialog(2, id, '菜单详情')
    },
    /**
     * 弹出form弹窗
     * @param type    类型0 新增 1编辑 2详情
     * @param id
     */
    popFormDialog(type, id, title) {
      popAutoHeightDialog('views/sysMenu/form', '600px', this.fetchList, { type, id, title })
    }
  }
}
</script>
<style>

</style>
